package com.ciwong.epaper.modules.me.ui.clazz;

import android.app.Activity;
import android.content.Context;
import android.widget.GridView;
import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.modules.me.adapter.ClassMemberAdapter;
import com.ciwong.epaper.modules.me.bean.ClassMember;
import com.ciwong.epaper.modules.me.bean.Clazz;
import com.ciwong.epaper.modules.me.dao.MeDao;
import com.ciwong.epaper.util.BaseExtCallBack;
import com.ciwong.epaper.util.IntentFlag;
import com.ciwong.epaper.util.LogOutUtil;
import com.ciwong.epaper.util.SerializableManager;
import com.ciwong.libs.utils.CWLog;
import com.ciwong.mobilelib.bean.UserInfoBase;
import com.ciwong.mobilelib.i.BaseCallBack;
import com.ciwong.mobilelib.ui.BaseActivity;

import java.io.Serializable;
import java.util.List;

/**
 * Created by neo on 2016/7/2.
 */

public class ClassMemberActivity extends BaseActivity{

    private GridView gv_class_member;
    private ClassMemberAdapter mClassMemberAdapter;
    private  Clazz mClazz;


    @Override
    protected void preCreate() {
        super.preCreate();
        mClazz = (Clazz) getIntent()
                .getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ);

    }


    @Override
    protected int setView() {
        return R.layout.activity_class_member;
    }


    @Override
    protected void findViews() {
        gv_class_member = (GridView) findViewById(R.id.gv_class_member);
    }

    @Override
    protected void initEvent() {
    }

    @Override
    protected void init() {

        mClassMemberAdapter = new ClassMemberAdapter(this,ClassMemberAdapter.PAGE_TYPE_CLASS_MEMBER);

        gv_class_member.setAdapter(mClassMemberAdapter);
        setTitleText(R.string.str_class_member);
    }

    @Override
    protected void loadData() {

        if (mClazz != null) {
            getNetClassList(mClazz);
        }

    }


    /**
     * 获取网络班级列表
     */
    private void getNetClassList(Clazz  clazz)
    {
        showCricleProgress();
        MeDao.getInstance().getClassMember(EApplication.BRAND_ID,clazz.getId(),1, 1,new BaseExtCallBack(ClassMemberActivity.this, EApplication.getInstance().getUserInfoBase().getUserId()+"")
        {

            @Override
            public void success(Object data)
            {
                List<ClassMember> users = (List<ClassMember>) data;
                refreshUI(users);
                // 更新本地班级列表
                hideCricleProgress();

                CWLog.d("ciwong", "#######users.size()#########"+users.size());

//                SerializableManager.getInstance().serialize(
//                        SerializableManager.SerializeKey.SHARE_KEY_CLASS_LIST,
//                        (Serializable) clazzs);
//                hideMiddleProgressBar( );

            }

            @Override
            public void failed(int errorCode, Object data)
            {
                super.failed(errorCode, data);
                hideCricleProgress( );
            }

            @Override
            public void failed(Object data)
            {
                hideCricleProgress();
            }
        });
    }


    /**
     *
     * @param userInfoBaseList
     * 成员列表
     */

    private void refreshUI(List<ClassMember> userInfoBaseList)
    {
        mClassMemberAdapter.clear();
        mClassMemberAdapter.addAll(userInfoBaseList);
    }
}
